#include "Sierpinski.hpp"
#include <cstdlib>
#include <ctime>
#include <iostream>

Sierpinski::Sierpinski() {
    std::srand(std::time(NULL));
    
    // vertices (equilateral triangle)
    pts.push_back(Point(0.57735, 0));
    pts.push_back(Point(0, 1));
    pts.push_back(Point(1.15470, 1));
}

Point Sierpinski::genPoint() {
    Point p(pts[std::rand() % pts.size()]); // choose a random point
    Point v(pts[std::rand() % 3]); // choose a random vertex
    Point newp((p.x - v.x)/2 + v.x, (p.y - v.y)/2 + v.y);
    pts.push_back(newp);
    return newp;
}

bool Sierpinski::canGenMore() {
    return pts.max_size() > pts.size();
}
